A good example of this, it is the representation of the stages in a research. In this case, it is represented four big stages of my PhD thesis research: Theoretical frame, Fieldwork, Analysis and Writing. Something benefitial of using this package is it allows a simple and comfortably visual with a simple code.
#install.packages("vistime")
library("vistime")
timeline_data <- data.frame(event = c("Theoretical frame", "Fieldwork", "Analysis", "Writing"),
start = c("2018-09-01", "2019-09-01", "2019-12-01", "2020-01-02"),
end = c("2019-09-01", "2020-01-15", "2020-10-01", "2021-09-01"),
group = "Stages of
the research")
A static option of the visualization:
gg_vistime(timeline_data)
An interactive option of the same visualization:
hc_vistime(timeline_data)
There is another interactive option:
vistime(timeline_data)
vistime(data, col.event = “event”, col.start = “start”, col.end = “end”, col.group = “group”, col.color = “color”, col.fontcolor = “fontcolor”, col.tooltip = “tooltip”, optimize_y = TRUE, linewidth = NULL, title = NULL, show_labels = TRUE, background_lines = NULL)
hc_vistime(data, col.event = “event”, col.start = “start”, col.end = “end”, col.group = “group”, col.color = “color”, optimize_y = TRUE, title = NULL, show_labels = TRUE)
gg_vistime(data, col.event = “event”, col.start = “start”, col.end = “end”, col.group = “group”, col.color = “color”, col.fontcolor = “fontcolor”, optimize_y = TRUE, linewidth = NULL, title = NULL, show_labels = TRUE, background_lines = NULL)
For this timeline, I used the ones done in the next webpage: https://www.themillerlab.io/post/timelines_in_r/
I used to work with many life history at the same time. And maybe you would be able to manage well with less than ten cases, however, when you got more than that it starts to get more problematic. Therefore, a useful way to work with all those cases is using one timeline for each one. It is important to highlith that this is a complementary tool for the researcher, however, it is not a repleasement of the deep information of a life history.
library(scales)
library(lubridate)
library(ggplot2)
library(tidyverse)
library(knitr)
library(timevis)
In this particular case, I will used as an example the academic event in which I had participated in one year.
CaseFrancisca <- data.frame(
Year = c(rep(c(2019), times =6), rep(c(2020), times =7)),
Months = c(4,6,6,7,10,10,5,7,7,7,7,7,7),
Days = c(24,7,13,9,1,3,20,2,7,13,14,15,23),
Milestones = c("BSA Annual Conference", "PGR Sociology Conference",
"MICRA Conference", "BSG Conference", "MICRA", "PhD Colloquium", "MICRA Conference", "BSG Conference", "Jornada de Redes 2020", "Panel Hispanic SUNBELT","SUNBELT", "SUNBELT", "ELSOC"),
Event_type= c("Presenter", "Presenter", "Presenter", "Presenter", "Organizer", "Organizer", "Organizer", "Presenter","Organizer","Organizer","Presenter", "Presenter", "Presenter"))
Add one column of the date.
CaseFrancisca$date <- with(CaseFrancisca, ymd(sprintf('%04d%02d%02d', CaseFrancisca$Year, CaseFrancisca$Months, CaseFrancisca$Days)))
CaseFrancisca <- CaseFrancisca[with(CaseFrancisca, order(date)), ]
kable(head(CaseFrancisca))
| Year | Months | Days | Milestones | Event_type | date |
|---|---|---|---|---|---|
| 2019 | 4 | 24 | BSA Annual Conference | Presenter | 2019-04-24 |
| 2019 | 6 | 7 | PGR Sociology Conference | Presenter | 2019-06-07 |
| 2019 | 6 | 13 | MICRA Conference | Presenter | 2019-06-13 |
| 2019 | 7 | 9 | BSG Conference | Presenter | 2019-07-09 |
| 2019 | 10 | 1 | MICRA | Organizer | 2019-10-01 |
| 2019 | 10 | 3 | PhD Colloquium | Organizer | 2019-10-03 |
Add one colours per type of event. In this case I used my role at the academic event, as a presenter or organizer.
Event_type_levels <- c("Presenter", "Organizer")
Event_type_colors <- c("#C00000", "#FFC000")
CaseFrancisca$Event_type <- factor(CaseFrancisca$Event_type, levels= Event_type_levels, ordered=TRUE)
positions <- c(0.5, -0.5, 1.0, -1.0, 1.25, -1.25, 1.5, -1.5)
directions <- c(1, -1)
Add positions and directions:
line_pos <- data.frame(
"date"=unique(CaseFrancisca$date),
"position"=rep(positions, length.out=length(unique(CaseFrancisca$date))),
"direction"=rep(directions, length.out=length(unique(CaseFrancisca$date))))
CaseFrancisca <- merge(x=CaseFrancisca, y=line_pos, by="date", all = TRUE)
Create a one month “buffer” at the start and end of the timeline
month_buffer <- 1
month_date_range <- seq(min(CaseFrancisca$date) - months(month_buffer), max(CaseFrancisca$date) + months(month_buffer), by='month')
month_format <- format(month_date_range, '%b')
month_df <- data.frame(month_date_range, month_format)
year_date_range <- seq(min(CaseFrancisca$date) - months(month_buffer), max(CaseFrancisca$date) + months(month_buffer), by='year')
Add format of year label
year_date_range <- as.Date(
intersect(
ceiling_date(year_date_range, unit="year"),
floor_date(year_date_range, unit="year")),
origin = "1970-01-01")
year_format <- format(year_date_range, '%Y')
year_df <- data.frame(year_date_range, year_format)
timeline_plot<-ggplot(CaseFrancisca,aes(x=date,y= position,
col=Event_type, label=CaseFrancisca$Milestones))
timeline_plot<-timeline_plot+labs(col="Milestones")
timeline_plot<-timeline_plot+scale_color_manual(values=Event_type_colors, labels=Event_type_levels, drop = FALSE)
timeline_plot<-timeline_plot+theme_classic()
timeline_plot<-timeline_plot+geom_hline(yintercept=0, color = "black", size=0.3)
timeline_plot<-timeline_plot+geom_segment(data=CaseFrancisca, aes(y=CaseFrancisca$position,yend=0,xend=CaseFrancisca$date), color='black', size=0.2)
timeline_plot<-timeline_plot+geom_point(aes(y=CaseFrancisca$position), size=3)
timeline_plot<-timeline_plot+theme(axis.line.y=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x =element_blank(),
axis.ticks.x =element_blank(),
axis.line.x =element_blank(),
legend.position = "bottom")
timeline_plot
timeline_plot<-timeline_plot+geom_text(data=month_df, aes(x=month_date_range,y=-0.15,label=month_format),size=3.5,vjust=0.5, color='black', angle=90)
timeline_plot<-timeline_plot+geom_text(data=year_df, aes(x=year_date_range, y=-0.25,label=year_format, fontface="bold"),size=3.5, color='black')
text_offset <- 0.2
absolute_value<-(abs(CaseFrancisca$position))
text_position<- absolute_value + text_offset
CaseFrancisca$text_position<- text_position * CaseFrancisca$direction
6.Now we can add the labels to the timeline for our milestones.
timeline_plot<-timeline_plot+geom_text(aes(y=CaseFrancisca$text_position, label=CaseFrancisca$Milestones),size=3.5, vjust=0.6)
timeline_plot
Plot an interactive timeline
#install.packages("plotly")
library(plotly)
ggplotly(timeline_plot)